#ifndef TRACKER_MGR_H
#define TRACKER_MGR_H

#include "tracker.h"
#include <map>
#include <memory>
#include <mutex>
#include <iostream>

class TrackerMgr 
{
public:
    TrackerMgr() {}
    ~TrackerMgr() {}

    void CreateTracker(int64_t k)
    {
        std::lock_guard<std::mutex> lock(m_oMutex);
        auto it = m_mapTracker.find(k);
        if (it != m_mapTracker.end()) 
        {
            std::cout << "Tracker is existed!" << std::endl;
            return;
        }

        m_mapTracker[k] = std::make_shared<tracker>(0.2, 100);
    }

    void DestroyTracker(int64_t k)
    {
        std::lock_guard<std::mutex> lock(m_oMutex);
        m_mapTracker.erase(k);
    }

    std::shared_ptr<tracker> GetTracker(int64_t k)
    {
        std::lock_guard<std::mutex> lock(m_oMutex);
        auto it = m_mapTracker.find(k);
        if (it != m_mapTracker.end()) 
        {
            return it->second;
        }

        std::cout << "Tracker is not found!" << std::endl;
        return std::shared_ptr<tracker>();
    }

private:
    std::mutex m_oMutex;
    std::map<int64_t, std::shared_ptr<tracker>> m_mapTracker;
};

#endif